app.controller("mqController", function($scope, $http) {

    $scope.mq_xml ;
    $scope.messageId ;
    $scope.correlationId ;
    $scope.priority;


    $scope.sendToMQ = function() {

        $http({
                method: 'post',
                url: '/mq/sendMq',
                data: {
                   "xmlContent": $scope.mq_xml,
                   "priority": $scope.priority,
                   "messageId":  $scope.messageId,
                   "correlationId": $scope.correlationId
                },
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                transformRequest: function(obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    }

             }).success(function(response) {
                   // if(response.status == '0000'){
                        alert(response.data);
                   // }
             });

    }

    $scope.getxml = function(num){
         $http({
            method: 'post',
            url: '/mq/getxml',
            data:{
                "tradeNo": num
            }
         }).success(function(response) {
                if(response.status == '0000'){
                    $scope.mq_xml = response.data;
                }
                if(response.status == '0001'){
                    alert(response.data)
                 }
         });

       // alert(num);
    }

    $scope.clearxml = function(){
        $scope.mq_xml = '';
    }

    $scope.random = function(){
      //  alert('180134009'+randomNum(1000,99999));
      //   alert(randomNum(1,9999999999991));
         $scope.messageId = '180130'+randomNum(1,99999999991);
         $scope.priority = 5;
         $scope.correlationId ='ASYN_CMD';
    }

    function randomNum(minNum,maxNum){
        switch(arguments.length){
            case 1:
                return parseInt(Math.random()*minNum+1,10);
            break;
            case 2:
                return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
            break;
                default:
                    return 0;
                break;
        }
    }

});